package com.marry.business.controller.user;

import com.common.web.service.HttpService;
import com.marry.business.service.user.MenuService;
import com.marry.business.service.user.RoleService;
import com.marry.business.service.user.UserService;
import com.marry.contract.vo.MenuVo;
import com.marry.contract.vo.RoleVo;
import com.marry.contract.vo.SysUser;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;


/**
 * @path：com.marry.controller.UserController.java
 * @className：UserController.java
 * @description: 用户信息
 * @author：杨超
 * @dateTime：2020/10/27 14:55
 * @editNote：LiuYun 2021/07/04 22:18:23
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private RoleService roleService;

    @Resource
    private MenuService menuService;

    @Resource
    private HttpService httpService;

    @ApiOperation(value = "查找用户名称", notes = "")
    @PostMapping(path = "findByName/{userName}")
    public Mono<SysUser> findByName(@PathVariable("userName") String userName){
        return userService.findByUsername(userName);
    }


    @ApiOperation(value = "根据角色ID获取权限", notes = "")
    @PostMapping("getRolePermission/{roleId}")
    public Flux<MenuVo> getRolePermission(@PathVariable("roleId") String roleId){
        return menuService.getMenuByRoleId(roleId);
    }

    @ApiOperation(value = "根据用户ID获取角色", notes = "")
    @PostMapping("getRoleByUserId/{userId}")
    public Flux<RoleVo> getRoleByUserId(@PathVariable("userId") String userId){
        return roleService.getRoleByUserId(userId);
    }

    @GetMapping("test")
    public Flux<SysUser> test(){
        return userService.findAll();
    }
}
